package com.sdust.controller;

import com.sdust.model.User;
import com.sdust.utils.jdbcUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/user/register")
public class RegisterController extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        try {
            Boolean res = jdbcUtils.addUser(new User(username, password));
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        req.getRequestDispatcher("/user/login.jsp").forward(req, resp);
    }
}
